package com.beiben.project.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.beiben.project.domain.ProjectTeam;
import com.beiben.project.service.IProjectTeamService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目组成员Controller
 * 
 * @author 熊国强
 * @date 2020-12-11
 */
@RestController
@RequestMapping("/project/team")
public class ProjectTeamController extends BaseController
{
    @Autowired
    private IProjectTeamService projectTeamService;

    /**
     * 查询项目组成员列表
     */
    @PreAuthorize("@ss.hasPermi('project:team:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectTeam projectTeam)
    {
        startPage();
        List<ProjectTeam> list = projectTeamService.selectProjectTeamList(projectTeam);
        return getDataTable(list);
    }

    /**
     * 导出项目组成员列表
     */
    @PreAuthorize("@ss.hasPermi('project:team:export')")
    @Log(title = "项目组成员", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ProjectTeam projectTeam)
    {
        List<ProjectTeam> list = projectTeamService.selectProjectTeamList(projectTeam);
        ExcelUtil<ProjectTeam> util = new ExcelUtil<ProjectTeam>(ProjectTeam.class);
        return util.exportExcel(list, "team");
    }

    /**
     * 获取项目组成员详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:team:query')")
    @GetMapping(value = "/{teamId}")
    public AjaxResult getInfo(@PathVariable("teamId") Long teamId)
    {
        return AjaxResult.success(projectTeamService.selectProjectTeamById(teamId));
    }

    /**
     * 新增项目组成员
     */
    @PreAuthorize("@ss.hasPermi('project:team:add')")
    @Log(title = "项目组成员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectTeam projectTeam)
    {
        return toAjax(projectTeamService.insertProjectTeam(projectTeam));
    }

    /**
     * 修改项目组成员
     */
    @PreAuthorize("@ss.hasPermi('project:team:edit')")
    @Log(title = "项目组成员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectTeam projectTeam)
    {
        return toAjax(projectTeamService.updateProjectTeam(projectTeam));
    }

    /**
     * 删除项目组成员
     */
    @PreAuthorize("@ss.hasPermi('project:team:remove')")
    @Log(title = "项目组成员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{teamIds}")
    public AjaxResult remove(@PathVariable Long[] teamIds)
    {
        return toAjax(projectTeamService.deleteProjectTeamByIds(teamIds));
    }

    /**
     * 查询项目组成员列表
     */
    @GetMapping("/userinfo")
    public AjaxResult userInfo(ProjectTeam projectTeam)
    {
        List<ProjectTeam> data = projectTeamService.selectProjectTeamList(projectTeam);
        return AjaxResult.success(data);
    }
}
